package com.grape.action.take_delivery;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.grape.action.common.BaseAction;
import com.grape.domain.take_delivery.Order;
import com.grape.service.take_delivery.OrderService;


@Controller
@Namespace("/order")
@ParentPackage("json-default")
@Scope("prototype")
public class OrderAction extends BaseAction<Order>{
	private static final long serialVersionUID = 1L;
	
	
	@Autowired
	private OrderService os;
	
	
	@Action(value="findByNum",results= {@Result(name="success",type="json"),@Result(name="input",type="json")})
	public String findByNum() {
		if (model==null || model.getOrderNum()==null) {
			return NONE;
		}
		
		Order order = os.findByOrderNum(model.getOrderNum());
		
		Map<String, Object> mp = new HashMap<>();
		if (order!=null) {
			mp.put("flag", true);
			mp.put("msg", order);
		}else {
			mp.put("flag", false);
		}
		
		
		
		ServletActionContext.getContext().getValueStack().push(mp);
		return SUCCESS;
	}
}
